﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Interop;
using GurLoader.GlobalHotkey;
using Moq;
using NUnit.Framework;

namespace GurLoaderWPF.Test.GlobalHotKey
{
    [TestFixture]
    public class DefaultHwndSourceWrapperTests
    {
        private long WS_BORDER = 0x00800000L;
        private Int32 CS_CLASSDC = 0x0040;

        [Test]
        [STAThread]
        public void CreateInstanceTest()
        {
            HwndSource hwd = new HwndSource(CS_CLASSDC, (int) WS_BORDER, 0, 0, 0, 20, 20, string.Empty, new IntPtr(0));
            var wrapper = new DefaultHwndSourceWrapper(hwd);

            Assert.IsNotNull(wrapper);
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void CreateInstanceNullSourceTest()
        {
            var wrapper = new DefaultHwndSourceWrapper(null);
        }

        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            return new IntPtr(0);
        }

        [Test]
        [STAThread]
        public void AddHookTest()
        {
            HwndSource hwd = new HwndSource(CS_CLASSDC, (int)WS_BORDER, 0, 0, 0, 20, 20, string.Empty, new IntPtr(0));
            var wrapper = new DefaultHwndSourceWrapper(hwd);

            Assert.IsNotNull(wrapper);

            wrapper.AddHook(WndProc);
        }

        [Test]
        [STAThread]
        public void RemoveHookTest()
        {
            HwndSource hwd = new HwndSource(CS_CLASSDC, (int)WS_BORDER, 0, 0, 0, 20, 20, string.Empty, new IntPtr(0));
            var wrapper = new DefaultHwndSourceWrapper(hwd);

            Assert.IsNotNull(wrapper);

            wrapper.RemoveHook(WndProc);
        }
    }
}
